package com.ourhealth.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.ourhealth.entity.PageResult;
import com.ourhealth.mapper.CheckItemMapper;
import com.ourhealth.pojo.CheckItem;
import com.ourhealth.service.CheckItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author dddddh
 */
@Service(interfaceClass = CheckItemService.class)
@Transactional(rollbackFor = Exception.class)
public class CheckItemServiceImpl implements CheckItemService{
    @Autowired
    private CheckItemMapper checkItemMapper;
    @Override
    /**
     * 添加检查项目信息
     * @param checkItem
     */
    public void add(CheckItem checkItem) {
        checkItemMapper.add(checkItem);
    }

    @Override
    public PageResult findPage(Integer currentPage, Integer pageSize, String queryString) {
        PageHelper.startPage(currentPage,pageSize);
        Page<CheckItem> page = checkItemMapper.findPage(queryString);
        return new PageResult(page.getTotal(),page.getResult());
    }

    @Override
    public void deleteCheckItem(int id) {
        long count = checkItemMapper.findCountByCheckItemId(id);
        if (count>0){
            throw new RuntimeException("当前索引被引用，无法删除");
        }
        checkItemMapper.deleteCheckItem(id);
    }

    @Override
    public CheckItem findCheckItemById(int id) {
        return checkItemMapper.findCheckItemById(id);
    }

    @Override
    public void editCheckItem(CheckItem checkItem) {
        checkItemMapper.editCheckItem(checkItem);
    }

    @Override
    public List<CheckItem> findAllCheckItem() {
        return checkItemMapper.findAllCheckItem();
    }
}
